<#
 #   It is recommended to test the script on a local machine for its purpose and effects. 
 #   ManageEngine Endpoint Central will not be responsible for any 
 #   damage/loss to the data/setup based on the behavior of the script.

 #   Description: Script is designed To Enable or Disable News and Interests on Taskbar
 #   Configuration Type - COMPUTER
 #   Refer: https://www.tenforums.com/tutorials/178178-how-enable-disable-news-interests-taskbar-windows-10-a.html
 #   Note: If the key was changed but not effective, advise the customer to reach out to Windows support, as the keys were taken from the Windows article.
 #>
 
# To Enable News and Interests on Taskbar use 1, To Disable News and Interests on Taskbar 0
$EnablePolicy = "0"

# Validate the argument (only 0 or 1 are acceptable)
if ($EnablePolicy -ne 0 -and $EnablePolicy -ne 1) {
    Write-Host "Invalid argument. Please provide 0 (disable) or 1 (enable)."
    exit
}

# Define the registry paths and values
$regPathAllowNewsAndInterests = "HKLM:\SOFTWARE\Microsoft\PolicyManager\default\NewsAndInterests"
$regPathWindowsFeeds = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds"
$valueNameAllowNewsAndInterests = "value"
$valueNameEnableFeeds = "EnableFeeds"

# Check if the paths exist, if not, create them
if (-not (Test-Path $regPathAllowNewsAndInterests)) {
    Write-Host "Registry path '$regPathAllowNewsAndInterests' does not exist. Creating path..."
    New-Item -Path "HKLM:\SOFTWARE\Microsoft\PolicyManager\default" -Name "NewsAndInterests" -Force
}

if (-not (Test-Path $regPathWindowsFeeds)) {
    Write-Host "Registry path '$regPathWindowsFeeds' does not exist. Creating path..."
    New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "Windows Feeds" -Force
}

# Set the registry value based on the argument
if ($EnablePolicy -eq 0) {
    Write-Host "Disabling the News and Interests policy..."
    Set-ItemProperty -Path $regPathAllowNewsAndInterests -Name $valueNameAllowNewsAndInterests -Value 0 -Type DWord
    Set-ItemProperty -Path $regPathWindowsFeeds -Name $valueNameEnableFeeds -Value 0 -Type DWord
} elseif ($EnablePolicy -eq 1) {
    Write-Host "Enabling the News and Interests policy..."
    Set-ItemProperty -Path $regPathAllowNewsAndInterests -Name $valueNameAllowNewsAndInterests -Value 1 -Type DWord
    Set-ItemProperty -Path $regPathWindowsFeeds -Name $valueNameEnableFeeds -Value 1 -Type DWord
}

Write-Host "Policy has been updated successfully."